/**
 * Copyright (c) 2000-2011 Liferay, Inc. All rights reserved.
 *
 * This library is free software; you can redistribute it and/or modify it under
 * the terms of the GNU Lesser General Public License as published by the Free
 * Software Foundation; either version 2.1 of the License, or (at your option)
 * any later version.
 *
 * This library is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
 * details.
 */

package doan.quanlycanbo.portlet.service.impl;

import java.util.List;

import com.liferay.counter.service.CounterLocalServiceUtil;
import com.liferay.portal.kernel.exception.PortalException;
import com.liferay.portal.kernel.exception.SystemException;
import com.liferay.portal.model.ResourceConstants;

import doan.quanlycanbo.portlet.NoSuchkhoidonviquanlyException;
import doan.quanlycanbo.portlet.model.khoidonviquanly;
import doan.quanlycanbo.portlet.service.base.khoidonviquanlyLocalServiceBaseImpl;

/**
 * 
 * @author Nguyen Tuan Vinh
 */
public class khoidonviquanlyLocalServiceImpl
	extends khoidonviquanlyLocalServiceBaseImpl {
	
	public List<khoidonviquanly> getAll() throws SystemException{
		return khoidonviquanlyPersistence.findAll();
	}
	
	public khoidonviquanly addKhoiDV(khoidonviquanly kdv1, long userId) throws SystemException{
		long makhoi = CounterLocalServiceUtil.increment(khoidonviquanly.class.getName());
		khoidonviquanly kdv2 = khoidonviquanlyPersistence.create(makhoi);
		kdv2.setGroupId(kdv1.getGroupId());
		kdv2.setCompanyId(kdv1.getCompanyId());
		kdv2.setLanguageId(kdv1.getLanguageId());
		kdv2.setTenkhoi(kdv1.getTenkhoi());

		try {
			resourceLocalService.addResources(kdv1.getCompanyId(), kdv1.getGroupId(), userId, 
					khoidonviquanly.class.getName(), kdv2.getPrimaryKey(), false, true, true);
		} catch (PortalException e) {
			e.printStackTrace();
		}
		
		return khoidonviquanlyPersistence.update(kdv2, false);
	}
	
	public khoidonviquanly updateKhoiDV(long makhoi, String tenkhoi) throws NoSuchkhoidonviquanlyException, SystemException{
		khoidonviquanly kdv = khoidonviquanlyPersistence.findByPrimaryKey(makhoi);
		kdv.setTenkhoi(tenkhoi);
		return khoidonviquanlyPersistence.update(kdv, false);
	}
	
	public khoidonviquanly deleteKhoiDV(long makhoi) throws NoSuchkhoidonviquanlyException, SystemException,PortalException{
		khoidonviquanly kdv = khoidonviquanlyPersistence.findByPrimaryKey(makhoi);
		return deleteKhoiDV(kdv);
	}
	
	public khoidonviquanly deleteKhoiDV(khoidonviquanly kdv) throws SystemException,PortalException{
		resourceLocalService.deleteResource(kdv.getCompanyId(), khoidonviquanly.class.getName(), ResourceConstants.SCOPE_INDIVIDUAL, kdv.getPrimaryKey());
		return khoidonviquanlyPersistence.remove(kdv);
	}
}








